#ifndef ASYNCSERVICE_H
#define ASYNCSERVICE_H

#include "../global.h"
#include <boost/asio/io_service.hpp>
#include <boost/function.hpp>

class AsyncService : protected boost::noncopyable
{
public:
    typedef boost::asio::io_service Implement;

    typedef boost::function< void () > Task;

public:
    AsyncService();
    ~AsyncService();

    Implement &implement();

    // Request a asynchronously task.
    // Process time unknown.
    void post(BOOST_ASIO_MOVE_ARG(Task) t);

    // Request a asynchronously task.
    // And process right now.
    void dispatch(BOOST_ASIO_MOVE_ARG(Task) t);

    // Start async service.
    void run();

    // Stop async service.
    void stop();

    // Determine the async service is stopped.
    bool stopped();

private:
    Implement m_impl;
};

#endif // ASYNCSERVICE_H
